package com.example.springblog.mapper;

import com.example.springblog.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BlogInfoMapper {
    @Select("select * from blog where delete_flag=0 order by create_time desc")
    List<BlogInfo> queryBlogList();

    @Select("select * from blog where id=#{id} and delete_flag=0")
    BlogInfo queryBlogById(int id);

    @Update("update blog set title=#{title},content=#{content} where id=#{id}")
    Integer updateBlog(BlogInfo blogInfo);

    @Update("update blog set delete_flag=1 where id=#{id}")
    Integer deleteBlog(int id);

    @Insert("insert into blog(title,content,user_id) values (#{title},#{content},#{userId})")
    Integer addBlog(BlogInfo blogInfo);

    @Select("select user_id from blog where blog.id=#{id}")
    Integer getUserIdByBlogId(Integer id);
}
